using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Policy;
using UnityEngine;

public class GravityController : MonoBehaviour
{
    public static GravityController Instance;
    [SerializeField] private float MaxFallingSpeed;
    [SerializeField] private float fallingSpeedDamping;

    public float FallingSpeedDamping => fallingSpeedDamping;

    private void Awake()
    {
        Instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void FunctionGravity(Rigidbody2D rigidbody)
    {
        if (rigidbody.velocity.y > MaxFallingSpeed)
        {
            var velocity = rigidbody.velocity;
            velocity -= new Vector2(velocity.x, fallingSpeedDamping);
            rigidbody.velocity = velocity;
        }
        else
        {
            rigidbody.velocity = new Vector2(rigidbody.velocity.x,MaxFallingSpeed);
        }
    }

    public void StopGravity(Rigidbody2D rigidbody)
    {
        rigidbody.velocity = new Vector2(rigidbody.velocity.x, 0f);
    }
}
